/*
 * @Author: your name
 * @Date: 2021-08-10 11:09:20
 * @LastEditTime: 2021-08-10 18:51:08
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \code-learn\src\auth\auth.controller.ts
 */
import {
  Request,
  Body,
  Controller,
  Post,
  Req,
  UseGuards,
} from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { User } from 'src/interfaces/user.interface';
import { AuthService } from './auth.service';
import { JwtAuthGuard } from './jwt-auth.guard';

@Controller('auth')
@ApiTags('用户验证模块')
export class AuthController {
  constructor(private readonly authService: AuthService) {}
  @Post('regist')
  @ApiOperation({
    summary: '用户注册',
  })
  async registUser(@Body() userDto: User) {
    return await this.authService.regist(userDto);
  }
  @Post('login')
  @ApiOperation({
    summary: '用户登录',
  })
  public async userLogin(@Body() userDto: User) {
    return await this.authService.login(userDto);
  }
  @Post('modify')
  @ApiOperation({
    summary: '用户信息修改',
  })
  @ApiBearerAuth('jwt')
  @UseGuards(JwtAuthGuard)
  public async modify(@Req() request: Request, @Body() userDto: User) {
    userDto.phone = request['user'].phone;
    return await this.authService.modifyOneByPhone(userDto);
  }
}
